/*
 * @Copyright: Citylife 2021
 * @Author: shaokui.gu
 * @Date: 2021-02-19 13:37:59
 * @Description: 
 */
import 'package:flutter/material.dart';

import '../base/base.dart';
import 'gesture_avoid_detector.dart';

class NavigationBar extends StatelessWidget {
  /// 左侧按钮
  final List<Widget> leftWidgets;

  /// 标题控件
  final Widget titleView;

  /// 右侧按钮
  final List<Widget> rightWidgets;

  /// 背景颜色
  final Color backgroundColor;

  /// 背景颜色
  final Color foregroundColor;

  /// 背景控件
  final Widget backgroundView;

  /// 背景图片
  final String backgroundImage;

  /// 标题
  final String title;

  NavigationBar({
    this.leftWidgets,
    this.titleView,
    this.title = "",
    this.rightWidgets,
    this.foregroundColor,
    this.backgroundColor,
    this.backgroundView,
    this.backgroundImage,
  });

  static backBar({
    String title,
    Color backgroundColor,
    Color foregroundColor,
    Widget backgroundView,
    String backgroundImage,
    List<Widget> rightWidgets,
  }) {
    return NavigationBar(
      leftWidgets: [
        GestureAvoidDetector(
          onTap: () {
            Get.back();
          },
          child: Text(
            "\uf053",
            style: TextStyle(
              fontFamily: IconFont,
              fontSize: 28.0,
              color: foregroundColor ?? theme.colors.defaultTitleColor,
            ),
          ),
        ),
      ],
      title: title,
      foregroundColor: foregroundColor,
      backgroundImage: backgroundImage,
      backgroundView: backgroundView,
      backgroundColor: backgroundColor,
      rightWidgets: rightWidgets,
    );
  }

  static titleBar({String title}) {
    return NavigationBar(
      title: title,
    );
  }

  static customBar({
    String title,
    Color backgroundColor,
    Color foregroundColor,
    Widget backgroundView,
    String backgroundImage,
    List<Widget> leftWidgets,
    List<Widget> rightWidgets,
  }) {
    return NavigationBar(
      title: title,
      foregroundColor: foregroundColor,
      backgroundImage: backgroundImage,
      backgroundView: backgroundView,
      backgroundColor: backgroundColor,
      leftWidgets: leftWidgets,
      rightWidgets: rightWidgets,
    );
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        Positioned(
          left: 0,
          right: 0,
          top: 0,
          bottom: 0,
          child: backgroundView ??
              (backgroundImage != null
                  ? Image.asset(
                      backgroundImage,
                      width: double.infinity,
                      height: double.infinity,
                      fit: BoxFit.cover,
                    )
                  : Container(
                      color: backgroundColor ??
                          theme.colors.navigationBarBackgroundColor,
                    )),
        ),
        SafeArea(
          bottom: false,
          child: Container(
            padding: EdgeInsets.symmetric(horizontal: 16.0.w),
            height: 44.0.w,
            child: Stack(
              children: [
                Align(
                  alignment: Alignment.centerLeft,
                  child: leftWidgets != null
                      ? Row(
                          mainAxisAlignment: MainAxisAlignment.start,
                          children: leftWidgets,
                        )
                      : null,
                ),
                Align(
                  alignment: Alignment.centerRight,
                  child: rightWidgets != null
                      ? Row(
                          mainAxisAlignment: MainAxisAlignment.end,
                          children: rightWidgets,
                        )
                      : rightWidgets,
                ),
                Align(
                  alignment: Alignment.center,
                  child: titleView ??
                      Text(
                        title ?? "",
                        style: TextStyle(
                          fontSize: 18.0.sp,
                          fontWeight: FontWeight.w500,
                          color: this.foregroundColor ??
                              theme.colors.naviBarTitleColor,
                        ),
                      ),
                ),
              ],
            ),
          ),
        ),
      ],
    );
  }
}
